package com.yufuchang;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.Map;

/**
 * Created by yufuchang on 2020/8/13.
 */
@RestController
public class GetController {

    @GetMapping("/get_path_param/{name}")
    public void getPathParams(@PathParam("name") String name){
        System.out.print("获取到的name参数："+name);
    }

    @GetMapping("/get_request_param")
    public void getRequestParams(@RequestParam("name") String name, @RequestParam("age") int age){
        System.out.print("我的名字是："+name+"我的年龄是："+age);
    }

    @GetMapping("/get_request_can_empty")
    public void getParamCanEmpty(@RequestParam(name = "name",required = false) String name){
        System.out.print("name可以为空，得到的名字是："+name);
    }

    @GetMapping("/get_param_with_default_value")
    public void getParamWithDefaultValue(@RequestParam(name = "name",defaultValue = "defaultname") String name){
        System.out.print("name带默认值，现在的名称是："+name);
    }

    @GetMapping("/get_param_as_map")
    public void getParamAsMap(@RequestParam Map<String,String> map){
        System.out.print("map内容："+map);
    }

    @GetMapping("/get_params_as_array")
    public void getParamsAsArray(@RequestParam("name") String[] array){
        System.out.print("数组第一个内容："+array[0]);
    }
}
